package com.trisoft.servlet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HttpUTurn
 */
public class HttpUTurn extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HttpUTurn() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("...executing doGet");
	    response.setContentType("text/html");
	    PrintWriter out = response.getWriter();
	    String title = "Reading Three Request Parameters";
	    out.println(ServletUtilities.headWithTitle(title) +
	                "<BODY>\n" +
	                "<H1 ALIGN=CENTER>" + title + "</H1>\n" +
	                "<UL>\n" +
	                "  <LI>param1: "
	                + request.getParameter("param1") + "\n" +
	                "  <LI>param2: "
	                + request.getParameter("param2") + "\n" +
	                "  <LI>param3: "
	                + request.getParameter("param3") + "\n" +
	                "</UL>\n" +
	                "</BODY></HTML>");		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("...executing doPost");
		BufferedReader in = new BufferedReader(request.getReader());
		String decodedString;
		while ((decodedString = in.readLine()) != null) {
			System.out.println(decodedString);
		}
		in.close();	
		
		response.setContentType("text/html");
	    PrintWriter out = response.getWriter();
	    String title = "Retachando el POST";
	    out.println(ServletUtilities.headWithTitle(title) +
	                "<BODY>\n" +
	                "<H1 ALIGN=CENTER>" + title + "</H1>\n" +
	                "Ohhh Yeeeahhh !!!!\n" +
	                "</BODY></HTML>");				
		
	}

}
